package event;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 主界面
 */
public class KWICApp {
    public static void main(String[] args) {
        JFrame frame = new JFrame("经典软件体系结构教学软件");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500, 300);

        JLabel label = new JLabel("请选择体系结构风格：");
        String[] architectures = {"主程序-子程序", "面向对象", "事件驱动", "管道-过滤器"};
        JComboBox<String> comboBox = new JComboBox<>(architectures);

        JTextArea outputArea = new JTextArea(10, 40);
        JButton processButton = new JButton("处理文件");

        processButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String selected = (String) comboBox.getSelectedItem();
                String result = "";
                switch (selected) {
                    case "主程序-子程序":
                        result = MainProgramSubroutine.process();
                        break;
                    case "面向对象":
                        result = new ObjectOriented().process();
                        break;
                    case "事件驱动":
                        result = new EventDriven().process();
                        break;
                    case "管道-过滤器":
                        result = PipeFilter.process();
                        break;
                }
                outputArea.setText(result);
            }
        });

        JPanel panel = new JPanel();
        panel.add(label);
        panel.add(comboBox);
        panel.add(processButton);
        frame.getContentPane().add(panel, "North");
        frame.getContentPane().add(new JScrollPane(outputArea), "Center");
        frame.setVisible(true);
    }
}
